package com.lanou.dllo.soccernews.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.bean.ImportBean;
import com.lanou.dllo.soccernews.volley.GetVolleyDatasUtil;

import java.util.List;

/**
 * Created by dllo on 15/10/29.
 */
public class ImportantAdapter extends RecyclerView.Adapter<ImportantAdapter.MyViewHolder> {

    private List<ImportBean.ListEntity> listEntityList;

    public void addData(List<ImportBean.ListEntity> listEntityList) {
        this.listEntityList = listEntityList;
        notifyDataSetChanged();
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.item_important, null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (listEntityList != null && listEntityList.size() > 0) {
            ImportBean.ListEntity listEntity = listEntityList.get(position);
            holder.competion_name.setText(listEntity.getCompetition_name());
            // Log.i("jjjj",listEntity.getCompetition_name()+"" );
            holder.team_a_name.setText(listEntity.getTeam_A_name());
            holder.team_b_name.setText(listEntity.getTeam_B_name());
           holder.gamework.setText("第" + listEntity.getGameweek() + "轮");
            holder.Tvlist.setText(listEntity.getTVList());
            if (listEntity.getTeam_A_logo() != null) {
                String imgUrl = listEntity.getTeam_A_logo();
                GetVolleyDatasUtil.getNetWorkImg(imgUrl, holder.a_logo);

            }

            if (listEntity.getTeam_B_logo() != null) {
                String imgUrl = listEntity.getTeam_B_logo();
                GetVolleyDatasUtil.getNetWorkImg(imgUrl, holder.b_logo);
            }


        }
    }

    @Override
    public int getItemCount() {
        return listEntityList != null && listEntityList.size() > 0 ? listEntityList.size() : 0;
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {

        private TextView
                competion_name, team_a_name, team_b_name, Tvlist, gamework;
        private ImageView a_logo, b_logo, flag_img;

        public MyViewHolder(View itemView) {
            super(itemView);

            competion_name = (TextView) itemView.findViewById(R.id.im_competition_name);
            team_a_name = (TextView) itemView.findViewById(R.id.im_team_a);
            team_b_name = (TextView) itemView.findViewById(R.id.im_team_b);


            Tvlist = (TextView) itemView.findViewById(R.id.TVlist);
            a_logo = (ImageView) itemView.findViewById(R.id.im_team_a_logo);
            b_logo = (ImageView) itemView.findViewById(R.id.im_team_b_logo);


            gamework = (TextView) itemView.findViewById(R.id.gamework);


        }
    }
}

